View Javadoc
1 /* 2 AntMake 3 4 Copyright (C) 2004 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsanleandro@yahoo.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: MakefileAmTemplate.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Template to generate Makefile.am files for Java folders. 37 * 38 * Last modified by: $Author: chous $ at $Date: 2004/01/25 20:20:15 $ 39 * 40 * File version: $Revision: 1.2 $ 41 * 42 * Project version: $Name: $ 43 * 44 * $Id: MakefileAmTemplate.java,v 1.2 2004/01/25 20:20:15 chous Exp $ 45 * 46 */ 47 package org.acmsl.antmake; 48 49 /* 50 * Importing some JDK classes. 51 */ 52 import java.io.File; 53 import java.text.MessageFormat; 54 import java.util.ArrayList; 55 import java.util.Iterator; 56 import java.util.Collection; 57 58 /*** 59 * Template to generate <i>Makefile.am</i> files for Java folders. 60 * @author <a href="mailto:jsanleandro@yahoo.es" 61 >Jose San Leandro</a> 62 * @version $Revision: 1.2 $ 63 */ 64 public abstract class MakefileAmTemplate 65 { 66 /*** 67 * The default header. 68 */ 69 public static final String DEFAULT_HEADER = 70 "#\n" 71 + "# AntMake\n" 72 + "#\n" 73 + "# Copyright (C) 2004 Jose San Leandro Armend?riz\n" 74 + "# jsanleandro@yahoo.es\n" 75 + "# chousz@yahoo.com\n" 76 + "#\n" 77 + "# This library is free software; you can redistribute it and/or\n" 78 + "# modify it under the terms of the GNU General Public\n" 79 + "# License as published by the Free Software Foundation; either\n" 80 + "# version 2 of the License, or (at your option) any later " 81 + "version.\n" 82 + "#\n" 83 + "# This library is distributed in the hope that it will be " 84 + "useful,\n" 85 + "# but WITHOUT ANY WARRANTY; without even the implied warranty " 86 + "of\n" 87 + "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " 88 + "GNU\n" 89 + "# General Public License for more details.\n" 90 + "#\n" 91 + "# You should have received a copy of the GNU General Public\n" 92 + "# License along with this library; if not, write to the Free " 93 + "Software\n" 94 + "# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA " 95 + "02111-1307 USA\n" 96 + "#\n" 97 + "# Thanks to ACM S.L. for distributing this library under the GPL " 98 + "license.\n" 99 + "# Contact info: jsanleandro@yahoo.es\n" 100 + "# Postal Address: c/Playa de Lagoa, 1\n" 101 + "# Urb. Valdecaba?as\n" 102 + "# Boadilla del monte\n" 103 + "# 28660 Madrid\n" 104 + "# Spain\n" 105 + " #################################################################" 106 + "#############\n" 107 + " #\n" 108 + " # Filename: $" + "RCSfile: $\n" 109 + " #\n" 110 + " # Author: AntMake\n" 111 + " #\n" 112 + " # Description: Defines the rules required to successfully build\n" 113 + " # each Java package.\n" 114 + " #\n" 115 + " # Last modified by: $" + "Author: $ at $" + "Date: $\n" 116 + " #\n" 117 + " # File version: $" + "Revision: $\n" 118 + " #\n" 119 + " # Project version: $" + "Name: $\n" 120 + " #\n" 121 + " # $" + "Id: $\n" 122 + " #\n\n"; 123 124 /*** 125 * The default Make-Rules body. 126 */ 127 public static final String DEFAULT_BODY = 128 "## Process this with automake to create Makefile.in\n" 129 + "\n" 130 + "include $(top_srcdir)/Make-rules\n" 131 + "\n" 132 + "{2}\n" // first-level subdirs 133 + "{3}" // Java sources subtemplate 134 + "PACKAGE_FNAME = {0}-{1}\n" // project name - package name 135 + "GCJ_INPUTS = $(java_Java)\n" 136 + "\n" 137 + "# Force repl.class to be built before sub-dirs.\n" 138 + "# Specifically, lib needs repl to compile scm files.\n" 139 + "all{4}: Makefile java-classes.stamp $(@GCJ_COMPILED_SELECTED@)\n"; 140 // "-recursive" if package with no source files 141 142 /*** 143 * The default SUBDIRS subtemplate. 144 */ 145 public static final String DEFAULT_SUBDIRS_SUBTEMPLATE = 146 "SUBDIRS = {0}\n"; 147 148 /*** 149 * The default java sources subtemplate. 150 */ 151 public static final String DEFAULT_JAVA_SOURCES_SUBTEMPLATE = 152 "java_sources =" 153 + "{0}\n\n"; // java_source_subtemplate 154 155 /*** 156 * The default java source subtemplate. 157 */ 158 public static final String DEFAULT_JAVA_SOURCE_SUBTEMPLATE = 159 " //\n {0}"; // java source file 160 161 /*** 162 * The header. 163 */ 164 private String m__strHeader; 165 166 /*** 167 * The Makefile.am body. 168 */ 169 private String m__strBody; 170 171 /*** 172 * The SUBDIRS subtemplate. 173 */ 174 private String m__strSubdirsSubtemplate; 175 176 /*** 177 * The java_sources subtemplate. 178 */ 179 private String m__strJavaSourcesSubtemplate; 180 181 /*** 182 * The Java source subtemplate. 183 */ 184 private String m__strJavaSourceSubtemplate; 185 186 /*** 187 * The project name. 188 */ 189 private String m__strProjectName; 190 191 /*** 192 * The package name. 193 */ 194 private String m__strPackageName; 195 196 /*** 197 * The first-level folder list. 198 */ 199 private Collection m__cFolders; 200 201 /*** 202 * The source files list. 203 */ 204 private Collection m__cSourceFiles; 205 206 /*** 207 * Builds a MakefileAmTemplate using given information. 208 * @param header the header. 209 * @param body the body. 210 * @param subdirsSubpackage the SUBDIRS subtemplate. 211 * @param javaSourcesSubpackage the java_sources subtemplate. 212 * @param javaSourceSubpackage the Java source subtemplate. 213 * @param projectName the project name. 214 * @param packageName the package name. 215 */ 216 public MakefileAmTemplate( 217 String header, 218 String body, 219 String subdirsSubtemplate, 220 String javaSourcesSubtemplate, 221 String javaSourceSubtemplate, 222 String projectName, 223 String packageName) 224 { 225 inmutableSetHeader(header); 226 inmutableSetBody(body); 227 inmutableSetSubdirsSubtemplate(subdirsSubtemplate); 228 inmutableSetJavaSourcesSubtemplate(javaSourcesSubtemplate); 229 inmutableSetJavaSourceSubtemplate(javaSourceSubtemplate); 230 inmutableSetProjectName(projectName); 231 inmutableSetPackageName(packageName); 232 } 233 234 /*** 235 * Builds a MakefileAmTemplate using given information. 236 * @param projectName the project name. 237 * @param packageName the package name. 238 */ 239 publicMakefileAmTemplate(String projectName, String packageName)/package-summary.html"> MakefileAmTemplate(String projectName, String packageName) 240 { 241 this( 242 DEFAULT_HEADER, 243 DEFAULT_BODY, 244 DEFAULT_SUBDIRS_SUBTEMPLATE, 245 DEFAULT_JAVA_SOURCES_SUBTEMPLATE, 246 DEFAULT_JAVA_SOURCE_SUBTEMPLATE, 247 projectName, 248 packageName); 249 } 250 251 /*** 252 * Specifies the header. 253 * @param header the new header. 254 */ 255 private void inmutableSetHeader(String header) 256 { 257 m__strHeader = header; 258 } 259 260 /*** 261 * Specifies the header. 262 * @param header the new header. 263 */ 264 protected void setHeader(String header) 265 { 266 inmutableSetHeader(header); 267 } 268 269 /*** 270 * Retrieves the header. 271 * @return such information. 272 */ 273 public String getHeader() 274 { 275 return m__strHeader; 276 } 277 278 /*** 279 * Specifies the body. 280 * @param body the new body. 281 */ 282 private void inmutableSetBody(String body) 283 { 284 m__strBody = body; 285 } 286 287 /*** 288 * Specifies the body. 289 * @param body the new body. 290 */ 291 protected void setBody(String body) 292 { 293 inmutableSetBody(body); 294 } 295 296 /*** 297 * Retrieves the body. 298 * @return such information. 299 */ 300 public String getBody() 301 { 302 return m__strBody; 303 } 304 305 /*** 306 * Specifies the SUBDIRS subtemplate. 307 * @param subdirsSubtemplate the new subtemplate. 308 */ 309 private void inmutableSetSubdirsSubtemplate(String subdirsSubtemplate) 310 { 311 m__strSubdirsSubtemplate = subdirsSubtemplate; 312 } 313 314 /*** 315 * Specifies the SUBDIRS subtemplate. 316 * @param subdirsSubtemplate the new subtemplate. 317 */ 318 protected void setSubdirsSubtemplate(String subdirsSubtemplate) 319 { 320 inmutableSetSubdirsSubtemplate(subdirsSubtemplate); 321 } 322 323 /*** 324 * Retrieves the SUBDIRS subtemplate. 325 * @return such information. 326 */ 327 public String getSubdirsSubtemplate() 328 { 329 return m__strSubdirsSubtemplate; 330 } 331 332 /*** 333 * Specifies the java_sources subtemplate. 334 * @param javaSourcesSubtemplate the new subtemplate. 335 */ 336 private void inmutableSetJavaSourcesSubtemplate(String javaSourcesSubtemplate) 337 { 338 m__strJavaSourcesSubtemplate = javaSourcesSubtemplate; 339 } 340 341 /*** 342 * Specifies the java_sources subtemplate. 343 * @param javaSourcesSubtemplate the new subtemplate. 344 */ 345 protected void setJavaSourcesSubtemplate(String javaSourcesSubtemplate) 346 { 347 inmutableSetJavaSourcesSubtemplate(javaSourcesSubtemplate); 348 } 349 350 /*** 351 * Retrieves the java_sources subtemplate. 352 * @return such information. 353 */ 354 public String getJavaSourcesSubtemplate() 355 { 356 return m__strJavaSourcesSubtemplate; 357 } 358 359 /*** 360 * Specifies the Java source subtemplate. 361 * @param javaSourceSubtemplate the new subtemplate. 362 */ 363 private void inmutableSetJavaSourceSubtemplate(String javaSourceSubtemplate) 364 { 365 m__strJavaSourceSubtemplate = javaSourceSubtemplate; 366 } 367 368 /*** 369 * Specifies the Java source subtemplate. 370 * @param javaSourceSubtemplate the new subtemplate. 371 */ 372 protected void setJavaSourceSubtemplate(String javaSourceSubtemplate) 373 { 374 inmutableSetJavaSourceSubtemplate(javaSourceSubtemplate); 375 } 376 377 /*** 378 * Retrieves the Java source subtemplate. 379 * @return such information. 380 */ 381 public String getJavaSourceSubtemplate() 382 { 383 return m__strJavaSourceSubtemplate; 384 } 385 386 /*** 387 * Specifies the project name. 388 * @param projectName the new project name. 389 */ 390 private void inmutableSetProjectName(String projectName) 391 { 392 m__strProjectName = projectName; 393 } 394 395 /*** 396 * Specifies the project name. 397 * @param projectName the new project name. 398 */ 399 protected void setProjectName(String projectName) 400 { 401 inmutableSetProjectName(projectName); 402 } 403 404 /*** 405 * Retrieves the project name. 406 * @return such information. 407 */ 408 public String getProjectName() 409 { 410 return m__strProjectName; 411 } 412 413 /*** 414 * Specifies the package name. 415 * @param packageName the new package name. 416 */ 417 private void inmutableSetPackageName(String packageName) 418 { 419 m__strPackageName = packageName; 420 } 421 422 /*** 423 * Specifies the package name. 424 * @param packageName the new package name. 425 */ 426 protected void setPackageName(String packageName) 427 { 428 inmutableSetPackageName(packageName); 429 } 430 431 /*** 432 * Retrieves the package name. 433 * @return such information. 434 */ 435 public String getPackageName() 436 { 437 return m__strPackageName; 438 } 439 440 /*** 441 * Specifies the first-level folders. 442 * @param folders the folder list. 443 */ 444 protected void setFolders(Collection folders) 445 { 446 m__cFolders = folders; 447 } 448 449 /*** 450 * Retrieves the first-level folders. 451 * @return such collection. 452 */ 453 protected Collection getFolders() 454 { 455 return m__cFolders; 456 } 457 458 /*** 459 * Adds a first-level folder. 460 * @param folder the first-level folder to add. 461 */ 462 public void addFolder(String folder) 463 { 464 setFolders(add(getFolders(), folder)); 465 } 466 467 /*** 468 * Specifies the source files. 469 * @param files the file list. 470 */ 471 protected void setSourceFiles(Collection files) 472 { 473 m__cSourceFiles = files; 474 } 475 476 /*** 477 * Retrieves the source files. 478 * @return such collection. 479 */ 480 protected Collection getSourceFiles() 481 { 482 return m__cSourceFiles; 483 } 484 485 /*** 486 * Adds a source file. 487 * @param file the source file to add. 488 */ 489 public void addSourceFile(String file) 490 { 491 if ( (file != null) 492 && (file.endsWith(".java"))) 493 { 494 setSourceFiles(add(getSourceFiles(), file)); 495 } 496 } 497 498 /*** 499 * Adds an item to given collection.. 500 * @param container the collection. 501 * @param item the item to add. 502 * @return the given collection, or a newly-created one 503 * if <code>container</code> was null. 504 */ 505 protected Collection add(Collection container, String item) 506 { 507 Collection result = null; 508 509 if (item != null) 510 { 511 if (container == null) 512 { 513 result = new ArrayList(); 514 } 515 else 516 { 517 result = container; 518 } 519 520 if (!result.contains(item)) 521 { 522 result.add(item); 523 } 524 } 525 526 return result; 527 } 528 529 /*** 530 * Retrieves the weaved <i>Makefile.am</i> file contents. 531 * @return such contents. 532 */ 533 public String toString() 534 { 535 StringBuffer t_sbResult = new StringBuffer(); 536 537 String t_strProjectName = getProjectName(); 538 String t_strPackageName = getPackageName(); 539 String t_strSubdirs = ""; 540 Collection t_cFolders = getFolders(); 541 Collection t_cSourceFiles = getSourceFiles(); 542 StringBuffer t_sbFolders = new StringBuffer(); 543 StringBuffer t_sbJavaSources = new StringBuffer(); 544 StringBuffer t_sbSourceFiles = new StringBuffer(); 545 boolean t_bRecursive = false; 546 547 AntMakeUtils t_AntMakeUtils = AntMakeUtils.getInstance(); 548 549 if (t_strProjectName != null) 550 { 551 MessageFormat t_Formatter = null; 552 553 t_sbResult.append(getHeader()); 554 555 if (t_cFolders != null) 556 { 557 Iterator t_itFolders = t_cFolders.iterator(); 558 559 while (t_itFolders.hasNext()) 560 { 561 // variable shortcut: t_bRecursive 562 // is defined to find out whether the rule 563 // in Makefile.am is "all" or "all-recursive". 564 // The point is if there're subfolders under 565 // current folder or not. However, the same 566 // variable has been used to omit one extra 567 // blank space just after SUBDIRS declaration. 568 if (t_bRecursive) 569 { 570 t_sbFolders.append(" "); 571 } 572 573 t_sbFolders.append( 574 t_AntMakeUtils.toSpecificPackage( 575 (String) t_itFolders.next())); 576 577 t_bRecursive = true; 578 } 579 580 t_Formatter = new MessageFormat(getSubdirsSubtemplate()); 581 582 t_strSubdirs = 583 t_Formatter.format( 584 new Object[] 585 { 586 t_sbFolders 587 }); 588 } 589 590 if (t_cSourceFiles != null) 591 { 592 Iterator t_itSourceFiles = t_cSourceFiles.iterator(); 593 594 t_Formatter = new MessageFormat(getJavaSourceSubtemplate()); 595 596 while (t_itSourceFiles.hasNext()) 597 { 598 t_sbSourceFiles.append( 599 t_Formatter.format( 600 new Object[] 601 { 602 " " + t_itSourceFiles.next() 603 })); 604 } 605 606 t_Formatter = new MessageFormat(getJavaSourcesSubtemplate()); 607 608 t_sbJavaSources.append( 609 t_Formatter.format( 610 new Object[] 611 { 612 t_sbSourceFiles 613 })); 614 } 615 616 t_Formatter = new MessageFormat(getBody()); 617 618 t_sbResult.append( 619 t_Formatter.format( 620 new Object[] 621 { 622 t_strProjectName.toLowerCase(), 623 t_AntMakeUtils.replaceAll( 624 t_strPackageName, File.separator, "-"), 625 t_strSubdirs, 626 t_sbJavaSources, 627 (t_bRecursive) 628 ? "-recursive" 629 : "" 630 })); 631 } 632 633 return t_sbResult.toString(); 634 } 635 }

This page was automatically generated by Maven